package cn.wolfcode.wolf2w.query;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.io.Serializable;

@Setter
@Getter
public class QueryObject  implements Serializable{
    private int currentPage=1; //当前页
    private int pageSize=10;   //每页显示记录数
    private String keyword;
    public String getKeyword(){
        if(keyword == null || "".equals(keyword.trim())){
            return null;
        }
        return  keyword;
    }

    private Pageable pageable;

    public Pageable getPageable(){
        if(pageable != null){
            return  this.pageable;
        }

       return PageRequest.of(this.getCurrentPage()-1, this.getPageSize(),
                Sort.Direction.ASC, "_id");
    }
}
